home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Information / PowerModule Development Info / SpeakPhrase ƒ / SpeakPhrase.c < prev    next >
Text File  |  1993-10-08  |  3KB  |  107 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  SpeakPhrase.c
  4. //
  5. //  This is a PowerModule that simply speaks the string in a STR# resource. This is a *very*
  6. //  simple example of how to write a PowerModule.  The code resource that is generated from
  7. //  this stuff must be of type 'PMod' and be merged into a file of type 'PMod' whose creator
  8. //  is of type 'PBin'.
  9. //
  10. //  ©1993 Scott A. Johnson
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////////////////////
  13.  
  14. #include <GestaltEqu.h>
  15. #include <Processes.h>
  16. #include <Speech.h>
  17.  
  18. // These are the 4 possible messages that PowerBar can send us
  19.  
  20. #define kInitModule 0
  21. #define kPerformAction 1
  22. #define kDoAbout 2
  23. #define kNoFiles 3
  24.  
  25. // Misc. alerts
  26.  
  27. #define kAboutSpeakPhrase 128
  28. #define kNeedSpeechManager 129
  29.  
  30. // resource defines
  31.  
  32. #define kMessageStringID 128
  33. #define kIndex2OurMsg    1
  34.  
  35. /* This is the main entry point for a PowerModule.  It is much like writing 'xDEF' type
  36.    code resources.  The message parameter tells us what we need to do.  The finderPSN
  37.    parameter is the process serial number of the Finder if we need it.  The wantFiles
  38.    parameter can be sent during the kInitModule processing to tell PowerBar to send an
  39.    array of FSSpec records our way.  The wantAliases parameter indicates that, if NOT 
  40.    set, PowerBar should attempt to resolve aliases before passing them to us.  The 
  41.    numFiles parameter will be the number of file specs passed in the next parameter, 
  42.    files.  This is only so, of course, if we requested the file list in the first place. */
  43.    
  44. pascal OSErr main (
  45.  
  46.         short                    message,            // what do do
  47.         ProcessSerialNumber        *finderPSN,            // Finder's process
  48.         Boolean                    *wantFiles,            // do we want to use files?
  49.         Boolean                    *wantAliases,        // do we want aliases if available
  50.         short                    numFiles,            // how many files to process
  51.         FSSpecArrayPtr            files  )            // the files demselves 
  52. {
  53.             
  54.     Str255  phrase;
  55.     long    speechAttrib;
  56.     OSErr    err=noErr;
  57.     
  58.     switch( message ) {
  59.     
  60.         case kInitModule:    
  61.         
  62.             /* Do any initial processing.  In our case, we need to make sure
  63.                the Speech Manager is present before we can proceed. */
  64.                
  65.             err = Gestalt( gestaltSpeechAttr, &speechAttrib );
  66.             if( err || !( speechAttrib & 0x01 ) ) {
  67.                 
  68.                 // OOPS!  Speech Manager not available.  Tell the user.
  69.                 
  70.                 (void)Alert( kNeedSpeechManager, NULL );
  71.                 err = (OSErr)1;            
  72.             } else {        
  73.                 *wantFiles = FALSE;                // don't want files or aliases
  74.                 *wantAliases = FALSE;        
  75.             }
  76.             break;
  77.             
  78.         case kPerformAction:
  79.         
  80.             /* This message is sent to us to actually do what we are here to do.
  81.                Note that our resource file is made "current" before we're called.  */
  82.             
  83.             GetIndString( phrase, kMessageStringID, kIndex2OurMsg );
  84.             if( phrase[0] > 0 ) {
  85.                 SpeakString( ( StringPtr )phrase );
  86.                 while( SpeechBusy() ) ;                    // don't leave before we're done!
  87.             }
  88.             break;
  89.             
  90.         case kDoAbout:
  91.         
  92.             /* This message is sent to us if the user pressed the COMMAND key 
  93.                while clicking our button.  We should tell 'em about ourself :)  */
  94.                
  95.             (void)Alert( kAboutSpeakPhrase, NULL );
  96.             break;
  97.     
  98.         case kNoFiles:
  99.         
  100.             /* This message will be sent to us when we requested files, but none
  101.                were available.  That is, the user clicked us but didn't select any
  102.                files before doing so! Not appropriate in our case. */
  103.             break;
  104.     }
  105.     
  106.     return( err );
  107. }